package com.sczmgk.hotline_pzh.utils;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.widget.CheckBox;
import android.widget.RadioButton;

/**
 * Created by bo on 2016/4/28.
 */
public class CheckboxUtils {
    public static void setCheckBoxImage(CheckBox checkBox, Context context){
//        float screenDensity = CommonUtils.getScreenDensity(context);
//        int r = (int)screenDensity *30;
//        int b = (int)screenDensity *30;
//        Drawable myImage = context.getResources().getDrawable(R.drawable.check_box_selector);//将资源转成Drawable
//        myImage.setBounds(1, 1, r, b);//设置图片的大小
//        checkBox.setCompoundDrawables(myImage, null, null, null);//设置图片在左边显示
//        checkBox.setGravity(Gravity.CENTER);
    }
    public static void setRadioButtonImage(RadioButton radioButton, Context context, int leftResId,int rightResId){
        float screenDensity = CommonUtils.getScreenDensity(context);
        int r1 = (int)(40*screenDensity);
        int b1 = (int)(40*screenDensity);

        int r2 = (int)(25*screenDensity);
        int b2 = (int)(25*screenDensity);
        Drawable leftImage = context.getResources().getDrawable(leftResId);//将资源转成Drawable
        Drawable rightImage = context.getResources().getDrawable(rightResId);//将资源转成Drawable
        leftImage.setBounds(1, 1, r1, b1);//设置图片的大小
        rightImage.setBounds(0, 0, r2, b2);//设置图片的大小
        radioButton.setCompoundDrawables( leftImage, null,rightImage, null);//设置图片在上面边显示
        radioButton.setGravity(Gravity.CENTER);
    }
    public static void setRadioButtonImage(RadioButton radioButton, Context context, int leftResId){
        float screenDensity = CommonUtils.getScreenDensity(context);
        float r1 = 25*screenDensity;
        float b1 = 25*screenDensity;
        int r = (int)r1;
        int b = (int)b1;
        Drawable leftImage = context.getResources().getDrawable(leftResId);//将资源转成Drawable
        leftImage.setBounds(1, 1, r, b);//设置图片的大小
        radioButton.setCompoundDrawables( null, leftImage,null, null);//设置图片在上面边显示
        radioButton.setGravity(Gravity.CENTER);
    }

}
